/*
 * Copyright (c) 2018 by TangChenBeiJian Information Technology Co.Ltd.
 *           All rights reserved
 */

package org.cx.exception;

import lombok.Getter;
import lombok.Setter;
import org.cx.constant.ServerCodeType;

import java.util.Objects;

import static org.cx.constant.ServerCodeType.SYSTEM_ERROR;

/**
 * class functional description
 *
 * @author Lin.Jianfei
 * @version 1.0.0
 * @since 2018-11-29
 */
@Getter
@Setter
public class BaseException extends RuntimeException {
    private static final long serialVersionUID = 1L;


    private int status;
    private ServerCodeType ErrorMessage;
    private String redirectUrl;

    public BaseException() {
        super();
    }

    public BaseException(String message) {
        super(message);
        this.status = -1;
    }

    public BaseException(int code, String message) {
        super(message);
        this.status = code;
    }

    public BaseException(int code, String message, String redirectUrl) {
        super(message);
        this.status = code;
        this.redirectUrl = redirectUrl;
    }

    /**
     * 避免获取方法栈快照信息
     */
    @Override
    public Throwable fillInStackTrace() {
        return this;
    }

    public int getStatus() {
        return this.status;
    }

    public static BaseException build(ServerCodeType message) {
        BaseException exception = new BaseException();
        exception.ErrorMessage = Objects.isNull(message) ? SYSTEM_ERROR : message;

        return exception;
    }

    public static BaseException build() {
        return build(null);
    }


}
